home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Palettes / MiscProgressPalette / MiscProgressView.subproj / MiscProgressBar.m < prev    next >
Text File  |  1995-04-12  |  3KB  |  161 lines

  1. //
  2. //    MiscProgressBar.h -- a simple view class for displaying progress bar
  3. //        Written and Copyright (c) 1993 by James Heiser.  (jheiser@adobe.com)
  4. //                Version 1.0.  All rights reserved.
  5. //
  6. //        This notice may not be removed from this source code.
  7. //
  8. //    This object is included in the MiscKit by permission from the author
  9. //    and its use is governed by the MiscKit license, found in the file
  10. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  11. //    for a list of all applicable permissions and restrictions.
  12. //    
  13.  
  14.  
  15. // Added two methoods -setTicsVisible: (BOOL) and -isTicsVisible:
  16. // Allows the user to select whether ticmarks are Visible or not.
  17. // James Heiser  Sat Sep 25 13:59:15 GMT-0800 1993
  18. //
  19. // Added two methoods -setTicsOverBar:(BOOL) and -isTicsOverBar
  20. // Allows the user to select whether ticmarks are drawn above or
  21. // below progress bar.
  22. // Don Yacktman  Mon Oct 18 22:58:52 MDT 1993
  23. //
  24. // Added two methoods -setTickColor:(NXColor) and -tickColor
  25. // Allows user to set color of ticmarks.
  26. // Don Yacktman  Mon Oct 18 22:58:52 MDT 1993
  27.  
  28. #import "MiscProgressBar.h"
  29.  
  30. #define MISC_DEFALUT_TICKS 24        // number of ticks to show + 1
  31.                                     // (so 24 divisions between 0-1 ratio)
  32.                                     
  33. #define MISC_DEFAULT_EMPHASIS 3        // every nth tick is longer...
  34.  
  35.  
  36. @implementation MiscProgressBar
  37.  
  38. - initFrame:(const NXRect *)frameRect
  39. {
  40.     [super initFrame:frameRect];
  41.     isTicsVisible = YES;
  42.     isTicsOverBar = NO;
  43.     numTicks = MISC_DEFALUT_TICKS;
  44.     emphasis = MISC_DEFAULT_EMPHASIS;
  45.     tc = NXConvertGrayToColor(NX_DKGRAY);
  46.     return self;
  47. }
  48.  
  49. - (NXColor)tickColor { return tc; }
  50.  
  51. - setTickColor:(NXColor)color
  52. {
  53.     tc = color;
  54.     return self;
  55. }
  56.  
  57. - renderTicks
  58. {
  59.     if (isTicsVisible == YES)  {
  60.         int linecount;
  61.         NXSetColor(tc);
  62.         for (linecount = 1; linecount <= numTicks; ++linecount)  {
  63.             int xcoord = (bounds.size.width / numTicks) * linecount;
  64.             PSnewpath();
  65.             PSmoveto(xcoord, 0);
  66.             if (linecount % emphasis)
  67.                 PSlineto(xcoord, (int)(bounds.size.height / 4));
  68.             else PSlineto(xcoord, (int)(bounds.size.height / 2));
  69.             PSstroke();
  70.         }
  71.     }
  72.     return self;
  73. }
  74.  
  75. - renderBar
  76. {
  77.     if (isTicsOverBar) {
  78.         [super renderBar];
  79.         [self renderTicks];
  80.     } else {
  81.         [self renderTicks];
  82.         [super renderBar];
  83.     }
  84.     return self;
  85. }
  86.  
  87. - setTicsVisible:(BOOL)aBool
  88. {
  89.     isTicsVisible = aBool;
  90.     [self display];
  91.     return self;
  92. }
  93.  
  94. - (BOOL)isTicsVisible
  95. {
  96.     return isTicsVisible;
  97. }
  98.  
  99. - setTicsOverBar:(BOOL)aBool
  100. {
  101.     isTicsOverBar = aBool;
  102.     [self display];
  103.     return self;
  104. }
  105.  
  106. - (BOOL)isTicsOverBar
  107. {
  108.     return isTicsOverBar;
  109. }
  110.  
  111. - setNumTicks:(int)anInt
  112. {
  113.     numTicks = MAX(anInt + 1, 1);
  114.     [self display];
  115.     return self;
  116. }
  117.  
  118. - (int)numTicks
  119. {
  120.     return (numTicks - 1);
  121. }
  122.  
  123. - setEmphasis:(int)anInt
  124. {
  125.     emphasis = MAX(anInt, 1);
  126.     [self display];
  127.     return self;
  128. }
  129.  
  130. - (int)emphasis
  131. {
  132.     return emphasis;
  133. }
  134.  
  135.  
  136. - read:(NXTypedStream*)stream
  137. {
  138.     [super read:stream];
  139.     NXReadTypes(stream, "ccii", &isTicsVisible, &isTicsOverBar,
  140.             &numTicks, &emphasis);
  141.     tc = NXReadColor(stream);
  142.     return self;
  143. }
  144.  
  145. - write:(NXTypedStream*)stream
  146. {
  147.     [super write:stream];
  148.     NXWriteTypes(stream, "ccii", &isTicsVisible, &isTicsOverBar,
  149.             &numTicks, &emphasis);
  150.     NXWriteColor(stream, tc);
  151.     return self;
  152. }
  153.  
  154. - (const char *)getInspectorClassName
  155. {
  156.      return "MiscProgressBarInspector";
  157. }
  158.  
  159.  
  160. @end
  161.